# include <cstdio>
# include <iostream>
# define MAXN 100023
using namespace std;

inline char getc() { 
    static char buf[1 << 18], *fs, *ft;
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}

inline int gn() { 
    int k = 0, f = 1;
    char c = getc();
    for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
    for(; isdigit(c); c = getc()) k = k * 10 + c - '0';
    return k * f;
}

int n, m;
bool c[MAXN];

int main() { 
    n = gn(), m = gn();
    for(int i = 1; i <= m; i++) { 
        int op = gn(), l = gn(), r = gn();
        if(!op) { 
            c[l - 1] = !c[l - 1];
            c[r] = !c[r];
        } else { 
            bool a = c[0];
            int cnt = 0;
            for(int i = 1; i <= r; i++) { 
                if(i >= l) cnt += a;
                a ^= c[i];
            }
            printf("%d\n", cnt);
        }
    }
}
